#!/usr/bin/python

def cyclepart(n, m):
    if n > m:
        n=n%m
    while n < m:
        n = n*10
    ql = [0]        #the quotient list
    rl = [n/10]       #the remainder list
    while True:
        q = n/m
        r = n%m
        #print q,r,ql,rl
        if r == 0:
            return []
        if r in rl:
            index = rl.index(r)
            return ql[index+1:] + [q]
        ql.append(q)
        rl.append(r)
        n = r*10
        
def main():
    m = 0
    for n in range(1,1000):
        if len(cyclepart(1,n))>m:
            m = n
    print m

if __name__ == '__main__':
    main()
    
